#include <cstdio>
#include <algorithm>

using namespace std;

__int64 a[ 41 ], f[ 41 ], ans;
int n, m;

void init( )
{
    int i;
    scanf("%d%d", &n, &m);
    for ( i = 0; i < n; i++ )
        scanf("%I64d", &a[ i ]);
    sort( a, a + n );
    f[ n - 1 ] = a[ n - 1 ];
    for ( i = n - 2; i >= 0; i-- )
        f[ i ] = f[ i + 1 ] & a[ i ];
    ans = 1;
    for ( i = 0; i < 61; i++ )
        ans *= 2;
}

void dfs( __int64 ret, int p, int step )
{
    int i;
    if ( ( ret & f[ p ] ) >= ans )
        return ;
    if ( ans > ret )
        ans = ret;
    if ( step == m )
        return ;
    for ( i = p; i < n; i++ )
        dfs( ret & a[ i ], i + 1, step + 1 );
}

int main( )
{
    int t, i, cas = 1;
    __int64 p = 1;
    for ( i = 0; i < 61; i++ )
        p *= 2;
    p--;
    scanf("%d", &t);
    while ( t-- )
    {
        init( );
        dfs( p, 0, 0 );
        printf("Case #%d: %I64d\n", cas++, ans);
    }
    return 0;
}
